#include "BlazeEngineImage.h"


BeImage::BeImage() :
	BeResource(),
	m_pvData(NULL)
{

}

BeImage::~BeImage()
{

}

void* BeImage::Lock()
{
	return m_pvData;
}

void BeImage::Unlock()
{

}

void BeImage::SetPixel(unsigned int uiX, unsigned int uiY, BeColor Color)
{
	if (uiX >= (unsigned int)m_Size.x || uiY >= (unsigned int)m_Size.y)
		return;

	switch(m_Type)
	{
	case ECT_R8G8B8:
		{
			unsigned char* pucDest = (unsigned char*)m_pvData + ( uiY * m_uiPitch ) + ( uiX * 3 );
			pucDest[0] = (unsigned char)Color.GetRed();
			pucDest[1] = (unsigned char)Color.GetGreen();
			pucDest[2] = (unsigned char)Color.GetBlue();
		} break;

	case ECT_A8R8G8B8:
		{
			unsigned int* puiDest = (unsigned int*)((unsigned char*)m_pvData + ( uiY * m_uiPitch ) + ( uiX << 2 ));
			*puiDest = Color.GetColor();
		} break;
	}
}

unsigned int BeImage::GetWidth()
{
	return (unsigned int)m_Size.x;
}

unsigned int BeImage::GetHeight()
{
	return (unsigned int)m_Size.y;
}

BeColor BeImage::GetPixel(unsigned int uiX, unsigned int uiY)
{
	if (uiX >= (unsigned int)m_Size.x || uiY >= (unsigned int)m_Size.y)
		return BeColor(0);

	switch(m_Type)
	{
	case ECT_A8R8G8B8:
		return ((unsigned int*)m_pvData)[uiY * (unsigned int)m_Size.x + uiX];
	case ECT_R8G8B8:
		{
			unsigned char* p = &((unsigned char*)m_pvData)[(uiY * 3) * (unsigned int)m_Size.x + (uiX * 3)];
			return BeColor(255, p[0], p[1], p[2]);
		}
	}

	return BeColor(0);
}

ColorType BeImage::GetFormat()
{
	return m_Type;
}

